# Created with pycharm
# author:ju bai
# Date:2021/7/20
# Time:19:10
from selenium import webdriver
import time
# 系统工具包
import os
# div对话框

driver = webdriver.Chrome()
# 本地HTML
url = "file:///"+os.path.abspath("D:/Python/selenium2html/modal.html")
driver.get(url)
driver.maximize_window()
time.sleep(3)

# 点击click
driver.find_element_by_id("show_modal").click()
time.sleep(3)
# 定位弹框中div中的元素
driver.find_element_by_id("click").click()
time.sleep(6)
# 关闭弹窗close
# xpath
# driver.find_element_by_xpath("//*[@id='myModal']/div[3]/button[1]").click()
# div
div = driver.find_element_by_class_name("modal-footer")
# 找到div之后再找button
buttons = div.find_elements_by_tag_name("button")
buttons[0].click()

time.sleep(6)
driver.quit()